<?php

class FeaturesResource extends Resource
{
    const ID = "features";

    public function GetId()
    {
        return self::ID;
    }

    public function GetFreshData()
    {
        $xml = @file_get_contents( FEATURES_FILE );
        $doc = Util::CreateXmlDocument( $xml );
        if ( $doc )
        {
            $features = array();
            $xpath = new XPathHelper($doc);
            $groupNodes = $xpath->GetNodes("/features/group");
            foreach ( $groupNodes as $groupNode )
            {
                $groupName = $xpath->GetText("name", $groupNode);
                $group = array();
                $featureNodes = $xpath->GetNodes("feature", $groupNode);
                foreach ( $featureNodes as $node )
                {
                    $feature = new Feature();
                    $feature->name  = $xpath->GetText("name", $node);
                    $feature->free  = Util::GetAsBoolean($xpath->GetText("free", $node));
                    $feature->pro   = Util::GetAsBoolean($xpath->GetText("pro", $node));
                    $group[] = $feature;
                }
                $features[$groupName] = $group;
            }

            Core::SetProperty('features_count', count($features));

            return $features;
        }
        return null;
    }
}

?>
